/*
 * Copy Right: Tencent ISUX
 * Project: QAM（Qzone模块化页面搭建平台）
 * Description: 模块、组件、框架管理
 * Author: kundy
 * date: 2011-12-5
 */

var code_id=functions.getRequest("id")*1;
var code_type=functions.getRequest("type")*1;
var code_action=functions.getRequest("action");


if(parent.location.href==qam_path){
parent.nav_set(code_type*1+4);

}

var code_text="";
switch(code_type){
	case 0:
		code_text="布局";
		break;
	case 1:
		code_text="容器";
		break;
	case 2:
		code_text="模块";
		break;	
	case 3:
		code_text="组件";
		break;	
	default:
		code_text="组件";
		break;	
}

//预览代码的图片
function preview_img(t){
	document.getElementById("shade_frame").src="img_adjust.htm?id="+t;
	$("#shade_layer").show();;
	$("#shade_layer").width(document.body.clientWidth);
	$("#shade_layer").height(document.body.clientHeight);
}


var code = {
	init:function(){
		$('#page_title').html(code_text+"管理");
		$(".like_select").click(function(){$(this).parent().find('.select_drop_down').css({visibility: "visible",display: "none"}).show();});
		$(".type_select").hover(
			function(){},
			function(){$(this).find('.select_drop_down').hide();}
		);
		$("#btn_add").click(function(){window.location.href="code.htm?type="+code_type});
		$("#page_up").click(function(){code.list_page(-1);});
		$("#page_down").click(function(){code.list_page(1);});
		$("#th_name").click(function(){code.list_page(0,'name');});
		$("#th_ident").click(function(){code.list_page(0,'ident');});
		$("#th_project_id").click(function(){code.list_page(0,'project_id');});
		$("#th_author").click(function(){code.list_page(0,'author');});
		$("#th_adjust_time").click(function(){code.list_page(0,'adjust_time');});
		$("#search_btn").click(function(){code.search();});
		
		
		$(".textarea_style").focus(function(){
			$(this).addClass("textarea_focus")
		});
		$(".textarea_style").blur(function(){
			$(this).removeClass("textarea_focus")
		});
	},
	addInit:function(){
		if(code_action=="edit"){
			code.edit(code_text);
			$("#btn_save").click(function(){code.update();});
			$('#page_title').html("修改"+code_text);
		}
		else{
			$("#btn_save").click(function(){code.add();});
			$('#page_title').html("添加"+code_text);
			
			$("#name").focusout(function () {
				this.value=this.value.replace(/\s/g,'');
				code.checkName(this.value);
			});
		}
		
		$("#btn_cancel").click(function(){window.location.href="code_list.htm?type="+code_type});
		$(".like_select").click(function(){$(this).parent().find('.select_drop_down').css({visibility: "visible",display: "none"}).show();});
		$(".type_select").hover(
			function(){},
			function(){$(this).find('.select_drop_down').hide();}
		);
		
		//不允许输入空格
		//鼠标离开、复制等！
		$("#name").mouseout(function () {
			this.value=this.value.replace(/\s/g,'');
		});
		
		$("#name").keyup(function () {
			this.value=this.value.replace(/\s/g,'');
		});
		$("#name").focusin(function () {
			$("#fhint_area_name").hide();
		});
		
		$(".textarea_style").focus(function(){
			$(this).addClass("textarea_focus")
			});
		/*
		$(".textarea_style").blur(function(){
			$(this).removeClass("textarea_focus")
			});
		*/
	},
	
	/*------------ 检查用户输入的名称 ------------*/
	checkName : function(project_name){
		if(project_name==""){
			$("#fhint_area_name").show();
			$("#fhint_area_name").removeClass('fhint_succeed').addClass('fhint_error');
			$("#fhint_ico").removeClass('ico_succeed').addClass('ico_error');
			$("#fhint_text").text("亲，名称要填的");
		}
		else
			this.checkNameValid(project_name);
    },
	
    checkNameValid : function(project_name){
		var data_area=[];
		data_area.push([ "name" , project_name ]);
		var data_str=functions.requestToString(data_area);

        $.ajax({
                url: cgipath+'code-checkName',type: 'POST', data: data_str, dataType: 'json',timeout: ajax_timeout, error: function(){notify.show(2,"请求数据失败，请刷新页面");},
				success:this.handelCheckNameValid
        });
    },

    handelCheckNameValid : function(feedback){
		//ret=0：已存在项目名称
        if(feedback.ret=="0"){
			$("#fhint_area_name").show();
			$("#fhint_area_name").removeClass('fhint_succeed').addClass('fhint_error');
			$("#fhint_ico").removeClass('ico_succeed').addClass('ico_error');
			$("#fhint_text").text("亲，项目名称已存在了，换一个吧");
			
        }
        else if(feedback.ret=="3"){
           $("#fhint_area_name").show();
		   $("#fhint_area_name").removeClass('fhint_error').addClass('fhint_succeed');
		   $("#fhint_ico").removeClass('ico_error').addClass('ico_succeed');
		   $("#fhint_text").text("亲，这个名字起不错！");
        }
    },
	
	search:function(){
		$('#parent_id_name').html("所有"+code_text);
		$('#parent_id').val(0);
		this.search_data=[];
		this.page=1;
		var search_text=$("#search_text").val();
		this.search_data.push([ "search_flag" , 1 ]);
		this.search_data.push([ "search_data" , search_text ]);
		this.showlist();
	},
	
	
    /*------------ 获取所有根项目信息 ------------*/
	search_data:[],
	page:1,//第几页
	reqnum:5,//每页显示多少条
	order:"id",//排序字段
	desc:1,//反序,0或空正常排序，1反序
	page_nums:0,//总页数
	
	
    showlist : function(){
		var data_area=[];
		data_area.push([ "page" , code.page ]);
		data_area.push([ "reqnum" , code.reqnum ]);
		data_area.push([ "type" , code_type ]);
		data_area.push([ "order" , code.order ]);
		data_area.push([ "desc" , code.desc ]);
		data_area.push([ "code_flag" , 1 ]);
		if(this.search_data.length>0)
			data_area=data_area.concat(this.search_data);
		
		var data_str=functions.requestToString(data_area);
        $.ajax({
                url: cgipath+'code-showlist', type: 'POST',data: data_str,dataType: 'json', timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:this.handleShowlist
        });
    },
	
     handleShowlist : function(feedback){
	
        if(feedback.ret=="0"){
			console.log(feedback.listdata);
            //显示项目列表
            var listdata=feedback.listdata;
			var innerhtml="";
            for(var i=0;i<listdata.length;i++){
                innerhtml+="<tr>";
				innerhtml+="<td><input type=\"checkbox\"></td>";
				innerhtml+="<td class=\"td_thumbnails\"><div class=\"img_wrap\"><a href=\""+(cgipath+listdata[i].path_htm)+"?"+Math.floor(Math.random()*10000)+"\" target=\"_blank\" title=\""+listdata[i].info+"\"><img src=\""+cgipath+listdata[i].path_thumb+"?"+Math.floor(Math.random()*10000)+"\" alt=\"\"></a><span class=\"module_name\">"+listdata[i].name+"</span></div></td>";
				innerhtml+="<td>"+listdata[i].ident+"</td>";
				innerhtml+="<td>"+listdata[i].project_name+"</td>";
				innerhtml+="<td>"+listdata[i].author+"</td>";
				innerhtml+="<td><span class=\"txt_auxiliary\">"+listdata[i].adjust_time+"</span></td>";
				innerhtml+="<td><p title=\""+listdata[i].used_pages+"\">当前："+listdata[i].used_times+"次</p><p>总共："+listdata[i].used_frequency+"次</p></td>";
				innerhtml+="<td>";
				innerhtml+="<a href=\"javascript:void(0)\" onclick=\"preview_img("+listdata[i].id+")\" target=\"_blank\"><i class=\"ico ico_preview_b\"></i>预览效果</a> ";
				if(code_type==1 || code_type==0)innerhtml+="<a href=\"pick_list.htm?id="+listdata[i].id+"\"><i class=\"ico ico_settings\"></i>参数设置</a> <BR>";
				/*
				if(listdata[i].type==2)innerhtml+="<a href=\"javascript:void(0)\" onclick=\"code.transition("+listdata[i].id+")\" target=\"_blank\"><i class=\"ico ico_preview_b\"></i>设为公用组件</a><BR> ";
				if(listdata[i].type==3)innerhtml+="<a href=\"javascript:void(0)\" onclick=\"code.transition("+listdata[i].id+")\" target=\"_blank\"><i class=\"ico ico_preview_b\"></i>设为模块</a><BR> ";
				*/
				innerhtml+="<a href=\"code.htm?action=edit&type="+listdata[i].type+"&id="+listdata[i].id+"\"><i class=\"ico ico_edit\"></i>修改</a> ";
				innerhtml+="<a href='javascript:void(0);' class=\"op_sub_href\" onclick=\"code.delConfirm("+listdata[i].id+");\" ><i class=\"ico ico_del\"></i>删除</a></td>";
				innerhtml+="</tr>";
            }
			//翻页组件
			code.page_nums=Math.ceil(feedback.nums/code.reqnum);
			if(code.page_nums<code.page)code.page=code.page_nums;//防止page_nums等于0的情况
			$("#page_nums").html(code.page+"/"+code.page_nums);
			if(code.page==1)
				$("#page_up").removeClass("ico_page_left").addClass("ico_page_left_n");
			else
				$("#page_up").removeClass("ico_page_left_n").addClass("ico_page_left");
			if(code.page_nums==code.page)
				$("#page_down").removeClass("ico_page_right").addClass("ico_page_right_n");
			else
				$("#page_down").removeClass("ico_page_right_n").addClass("ico_page_right");
				
			$("#code_list").html(innerhtml);
        }
        else{
             message.show("message_div","",feedback.msg,4);
        }
    },
	
	list_page:function(t,order){
		if(order!=undefined && order!="")
		{
			code.order=order;
			if(code.desc*1==1)code.desc=0;
			else code.desc=1;
		}
	
		code.page=code.page-(-1)*t;
		if(code.page<=0)code.page=1;
		else if(code.page>code.page_nums) code.page=code.page_nums;
		code.showlist();
	},
	
	project_data:[],
	loadProject:function(){
		var data_area=[];
		var data_str=functions.requestToString(data_area);
        $.ajax({
                url: cgipath+'project-showStruct',type: 'POST',data: data_str,dataType: 'json',timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:function(feedback){
					code.project_data=feedback.listdata;
					code.parentList();
					code.addInit();
				}
        });
	},
	
		/*------------ 获取所有父项目信息ID列表 ------------*/

     parentList : function(){
		//显示父项目列表
		var ul="<ul>";
		for(var i=0;i<code.project_data.length;i++){
			ul+="<li><a onclick=\"code.chooseParentId("+i+")\" id=\""+code.project_data[i].parent.id+"\" name=\""+code.project_data[i].parent.name+"\" href=\"javascript:void(0);\">"+code.project_data[i].parent.name+"</a></li>";
		}
		ul+="</ul>";
		$("#parent_id_list").html(ul);
		$(".like_select").click(function(){$(this).parent().find('.select_drop_down').css({visibility: "visible",display: "none"}).show();});
		$(".type_select").hover(
			function(){},
			function(){$(this).find('.select_drop_down').hide();}
		);
    },
	chooseParentId : function(t){
         $('#parent_id_list').css('display', 'none');
		 $('#sub_id_name').html("选择子项目");
		 $('#sub_id').val(-1);
		 if(t==-1){
			$('#parent_id_name').html("所有项目");
			$('#parent_id').val(-1);
		 }
		 else{
			$('#parent_id_name').html(code.project_data[t].parent.name);
			$('#parent_id').val(code.project_data[t].parent.id);
			this.subProjectList(t);
		}
    },
	/*------------ 获取子项目信息ID列表 ------------*/
     subProjectList : function(t){
		var ul="<ul>";
		ul+="<li><a onclick=\"code.chooseChildProjectList(-1)\" id=\"0\" name=\"选择子项目\" href=\"javascript:void(0);\">选择子项目</a></li>";
		for(var i=0;i<code.project_data[t].child.length;i++){
			ul+="<li><a onclick=\"code.chooseChildProjectList("+t+","+i+")\" id=\""+code.project_data[t].child[i].id+"\" name=\""+code.project_data[t].child[i].name+"\" href=\"javascript:void(0);\">"+code.project_data[t].child[i].name+"</a></li>";
		}
		ul+="</ul>";
		$("#sub_id_list").html(ul);
		$(".like_select").click(function(){$(this).parent().find('.select_drop_down').css({visibility: "visible",display: "none"}).show();});
		$(".type_select").hover(
			function(){},
			function(){$(this).find('.select_drop_down').hide();}
		);
    },
	
	chooseChildProjectList : function(t1,t2){
         $('#sub_id_list').css('display', 'none');
		 if(t1==-1){
			$('#sub_id_name').html("选择子项目");
			$('#sub_id').val(0);
		 }
		 else{
			$('#sub_id_name').html(code.project_data[t1].child[t2].name);
			$('#sub_id').val(code.project_data[t1].child[t2].id);
		 }
    },
	
	
	
	
	
	/*------------ 获取所有根项目信息ID列表 ------------*/
		projectParentList : function(){
		var data_area=[];
		data_area.push([ "root_flag" , 1 ]);
		data_area.push([ "search_flag" , 0 ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
                url: cgipath+'project-showlist',type: 'POST',data: data_str,dataType: 'json',timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:this.handleprojectParentList
        });
    },

     handleprojectParentList : function(feedback){
        if(feedback.ret=="0"){
            //显示项目列表
            var project_list_array=feedback.listdata;
			var ul="<ul>";
			ul+="<li><a onclick=\"code.chooseProjectParentList(this)\" id=\"0\" name=\"所有"+code_text+"\" href=\"javascript:void(0);\">所有"+code_text+"</a></li>";
            for(var i=0;i<project_list_array.length;i++){
				if(project_list_array[i].id!=1)ul+="<li><a onclick=\"code.chooseProjectParentList(this)\" id=\""+project_list_array[i].id+"\" name=\""+project_list_array[i].name+"\" href=\"javascript:void(0);\">"+project_list_array[i].name+code_text+"</a></li>";

            }
			ul+="</ul>";
			$("#parent_id_list").html(ul);
			$('#parent_id_name').html("所有"+code_text);
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	chooseProjectParentList : function(obj){
		 var id_old=$("#parent_id").val()
		 $('#search_text').val("");
		 $('#parent_id_list').css('display', 'none');
		 $('#parent_id_name').html($(obj).attr("name"));
		 $('#parent_id').val($(obj).attr("id"));
		 
		this.search_data=[];
		this.page=1;
		if($(obj).attr("id")!=0){
			this.search_data.push([ "search_flag" , 0 ]);
			this.search_data.push([ "project_id" , $(obj).attr("id") ]);
		}
		this.showlist();
    },
	
	
	
	
    /*------------ 添加一段代码 ------------*/
    add : function(){
        notify.show(1,"正在保存，请稍候...");
		var project_id=0;
		if($("#sub_id").val()*1>0)
			project_id=$("#sub_id").val();
		else
			project_id=$("#parent_id").val();
		var data_area=[];
		data_area.push([ "name" , $('#name').val() ]);
		data_area.push([ "info" , $('#info').val() ]);
		data_area.push([ "html" , $('#html').val() ]);
		data_area.push([ "css" , $('#css').val() ]);
		data_area.push([ "css_preview" , $('#css_preview').val() ]);
		data_area.push([ "js" , $('#js').val() ]);
		data_area.push([ "project_id" , project_id ]);
		data_area.push([ "type" , code_type ]);

		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'code-add',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handleAdd
        });
    },

    handleAdd : function (feedback){
		notify.close();
        if(feedback.ret=="0"){
			//检测图片采集结果
			var str="";
			var html_nums=feedback.img_status.html.nums.bad+feedback.img_status.html.nums.good;
			var css_nums=feedback.img_status.css.nums.bad+feedback.img_status.css.nums.good;
			str+="保存成功";
			if(html_nums>0 || css_nums>0)str+="<BR /><BR /><HR />";
			if(html_nums>0){
				str+="<BR>在html中检测到<span style=\"color:#E57C7E;font-weight:bold;\">"+html_nums+"</span>张图片";
				if(feedback.img_status.html.nums.bad>0){
					str+="其中<span style=\"color:#E57C7E;font-weight:bold;\">"+feedback.img_status.html.nums.bad+"</span>张图片采集失败，图片列表如下<BR>";
					for(var i=0;i<feedback.img_status.html.img_list.length;i++){
						str+="&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:#AAAA62\">"+feedback.img_status.html.img_list[i]+"</span><BR>";
					}
				}else{
					str+="并成功采集！<BR>"
				}
			}
			if(css_nums>0){
				str+="<BR>在css中检测到<span style=\"color:#E57C7E;font-weight:bold;\">"+css_nums+"</span>张图片";
				if(feedback.img_status.css.nums.bad>0){
					str+="，其中<span style=\"color:#E57C7E;font-weight:bold;\">"+feedback.img_status.css.nums.bad+"</span>张图片采集失败，图片列表如下:<BR>";
					for(var i=0;i<feedback.img_status.css.img_list.length;i++){
						str+="&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:#AAAA62\">"+feedback.img_status.css.img_list[i]+"</span><BR>";
					}
				}else{
					str+="并成功采集！<BR>"
				}
			}
			if(html_nums>0 || css_nums>0)str+="<BR /><HR />"
			if(feedback.img_status.html.nums.bad+feedback.img_status.css.nums.bad>0)str+="<span style=\"color:#D17CC4\">请检查图片名称，建议不要使用SVN的绝对路径</span>"
			message.show("message_div","","添加成功",3,"","window.location.href='code_list.htm?type="+code_type+"';");
        }
        else{
            message.show("message_div","",feedback.msg,4);
			$("#btn_save").removeClass("btn_dis").addClass("btn_ok");
			$("#btn_save").click(function(){code.add();});
        }
    },
	
	/*------------ 编辑 ------------*/
    edit : function(){
		var data_area=[];
		data_area.push([ "id" , code_id ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
                url: cgipath+'code-getinfo',type: 'POST',data: data_str,dataType: 'json',timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:this.handleedit
        });
    },

     handleedit : function(feedback){
        if(feedback.ret=="0"){
            var record=feedback.record;
			$("#name").val(record.name);
			$("#info").val(record.info);
			$("#html").html(record.html);
			$("#js").html(record.js);
			$("#css").html(record.css);
			$("#css_preview").html(record.css_preview);
			if(record.parent_project_id==0){
				$("#parent_id").val(record.project_id);
				$("#parent_id_name").html(record.project_name);
			}
			else{
				$("#sub_id").val(record.project_id);
				$("#sub_id_name").html(record.project_name);
				$("#parent_id").val(record.parent_project_id);
				$("#parent_id_name").html(record.parent_project_name);
			}
			
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	/*------------ 保存一个项目 ------------*/
	update : function(){
		notify.show(1,"正在保存，请稍候...");
		$("#btn_save").unbind("click");
		$("#btn_save").removeClass("btn_ok").addClass("btn_dis");
        //收集项目信息
		var project_id=0;
		if($("#sub_id").val()*1>0)
			project_id=$("#sub_id").val();
		else
			project_id=$("#parent_id").val();
		var data_area=[];
		data_area.push([ "id" , code_id ]);
		data_area.push([ "name" , $('#name').val() ]);
		data_area.push([ "info" , $('#info').val() ]);
		data_area.push([ "html" , $('#html').val() ]);
		data_area.push([ "css" , $('#css').val() ]);
		data_area.push([ "css_preview" , $('#css_preview').val() ]);
		data_area.push([ "js" , $('#js').val() ]);
		data_area.push([ "project_id" , project_id ]);

		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'code-update',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handleUpdate
        });
    },

    handleUpdate : function (feedback){
		notify.close();
        if(feedback.ret=="0"){
			//检测图片采集结果
			var str="";
			var html_nums=feedback.img_status.html.nums.bad+feedback.img_status.html.nums.good;
			var css_nums=feedback.img_status.css.nums.bad+feedback.img_status.css.nums.good;
			str+="保存成功";
			if(html_nums>0 || css_nums>0)str+="<BR /><BR /><HR />";
			if(html_nums>0){
				str+="<BR>在html中检测到<span style=\"color:#E57C7E;font-weight:bold;\">"+html_nums+"</span>张图片";
				if(feedback.img_status.html.nums.bad>0){
					str+="其中<span style=\"color:#E57C7E;font-weight:bold;\">"+feedback.img_status.html.nums.bad+"</span>张图片采集失败，图片列表如下<BR>";
					for(var i=0;i<feedback.img_status.html.img_list.length;i++){
						str+="&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:#AAAA62\">"+feedback.img_status.html.img_list[i]+"</span><BR>";
					}
				}else{
					str+="并成功采集！<BR>"
				}
			}
			if(css_nums>0){
				str+="<BR>在css中检测到<span style=\"color:#E57C7E;font-weight:bold;\">"+css_nums+"</span>张图片";
				if(feedback.img_status.css.nums.bad>0){
					str+="，其中<span style=\"color:#E57C7E;font-weight:bold;\">"+feedback.img_status.css.nums.bad+"</span>张图片采集失败，图片列表如下:<BR>";
					for(var i=0;i<feedback.img_status.css.img_list.length;i++){
						str+="&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:#AAAA62\">"+feedback.img_status.css.img_list[i]+"</span><BR>";
					}
				}else{
					str+="并成功采集！<BR>"
				}
			}
			if(html_nums>0 || css_nums>0)str+="<BR /><HR />"
			if(feedback.img_status.html.nums.bad+feedback.img_status.css.nums.bad>0)str+="<span style=\"color:#D17CC4\">请检查图片名称，建议不要使用SVN的绝对路径</span>"
			message.show("message_div","提示",str,1,"","history.go(-1)");
		
        }
        else{
			console.log(feedback.test);
            message.show("message_div","",feedback.msg,4);
			$("#btn_save").removeClass("btn_dis").addClass("btn_ok");
			$("#btn_save").click(function(){code.update();});
        }
    },
	
	/*------------ 获取一条信息 ------------*/
    getinfoImg : function(){
		var data_area=[];
		data_area.push([ "id" , code_id ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
                url: cgipath+'code-getinfo',type: 'POST',data: data_str,dataType: 'json',timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:this.handlGetinfoImg
        });
    },

     handlGetinfoImg : function(feedback){
        if(feedback.ret=="0"){
            $('#photo')[0].src=cgipath+feedback.record.path_img+"?"+Math.random();
			$('#thumb')[0].src=cgipath+feedback.record.path_thumb+"?"+Math.random();
			$('#photo').imgAreaSelect({  handles: true,fadeSpeed: 200, onSelectChange: preview });
			$('#photo')[0].onload=function(){
				$('#container').css("margin-left",$('#container').width()/2*(-1));
				$('.imgareaselect-selection').click(function(){alert("sdf")});
			}
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },

	
	 /*------------ 删除项目 ------------*/
	 
	delConfirm:function(id){
		message.show("message_div","","确实要删除吗？",2,"","code.del("+id+");");
	},
	
    del : function(id){
		var data_str="&id="+id;
        $.ajax({
            url:cgipath + 'code-del',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handledel
        });
    },

    handledel : function (feedback){
        if(feedback.ret=="0"){
            message.show("message_div","","删除成功",3,"","window.location.reload();");
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	
	/*------------ 模块、组件转换 ------------*/
	transition : function(t){
        //收集项目信息
		var data_area=[];
		data_area.push([ "id" , t ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'code-transition',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handletransition
        });
    },

    handletransition : function (feedback){
		console.log(feedback);
        if(feedback.ret=="0"){
			message.show("message_div","","转换成功",3,"","code.showlist();");
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	 /*------------ 保存截图 ------------*/
    adjustImg : function(){
		var data_area=[];
		data_area.push([ "code_id" , code_id ]);
		data_area.push([ "x" , x ]);
		data_area.push([ "y" , y ]);
		data_area.push([ "w" , w ]);
		data_area.push([ "h" , h ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'image-adjust',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handladjustImg
        });
    },

    handladjustImg : function (feedback){
        if(feedback.ret=="0"){
            history.go(0);
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	
	 /*------------ 重新生成截图 ------------*/
	createImg : function(){
		var data_area=[];
		data_area.push([ "code_id" , code_id ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'code-snapshot',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handlrecreateImg
        });
    },

    handlrecreateImg : function (feedback){
        if(feedback.ret=="0"){
            history.go(0);
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    }
	
	

}



function html_set(t){
	var add_data="";
	if(t=='tab')add_data="\t";
	else if(t=='obj_div')add_data="<div class=\"\">\n\t<div class=\"hd\"></div>\n\t<div class=\"bd\"></div>\n\t<div class=\"ft\"></div>\n</div>";
	else if(t=='div')add_data="<div></div>";
	else if(t=='span')add_data="<span></span>";
	else if(t=='p')add_data="<p></p>";
	else if(t=='class')add_data=" class=\"\" ";
	else if(t=='ul')add_data="<ul><li></li></ul>";
	else if(t=='img')add_data="<img src=\"\" />";
	else if(t=='table')add_data="<table><tr><td></td></tr></table>";
	else if(t=='a')add_data="<a href=\"#\"></a>";
	else if(t=='place')add_data="<img src=\""+cgipath+"img.php?100x100\" />";
	if(t==2)add_data="<div class=\"\"></div>";
	functions.textareaInsertText($('#html')[0],add_data);
}


function html_add(t){
	var add_data="";
	if(t==0)add_data=" data_container=1 ";
	else if(t==1)add_data="{visible name=\"name\"}";
	else if(t==2)add_data="{/visible}";
	else if(t==3)add_data="{loop name=\"name\"}";
	else if(t==4)add_data="{/loop}";
	functions.textareaInsertText($('#html')[0],add_data);
}

function html_more(){
	$("#code_attr_more").show();
}








